package com.cxy.common.aop

import android.app.Activity
import com.fy.baselibrary.statusbar.MdStatusBar
import com.fy.baselibrary.statusbar.StatusBarContentColor
import org.aspectj.lang.JoinPoint
import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Before

/**
 * description 定义切面类，动态 插入状态栏 导航栏 着色代码
 * Created by fangs on 2021/1/11 14:50.
 */
@Aspect
class StatusBarAspect {

    @Before("execution(* com.fy.baselibrary.application.mvvm.IBaseMVVM.setContentLayout(..))")
    fun iBaseStatusBarHook(joinPoint: JoinPoint) {
        setCommonStatusColor(joinPoint)
    }

    //统一状态栏 导航栏 样式
    private fun setCommonStatusColor(joinPoint: JoinPoint) {
        val obj: Any = joinPoint.`this` ?: return
        val activity: Activity = obj as? Activity ?: return

        MdStatusBar.StatusBuilder.init()
            .setStatusColor(0, 0, "statusBar")
            .setNavColor(0, 0, "navBar")
            .setApplyNav(true)
            .setColorBar(activity)
    }

    //状态栏 白色，状态栏内容深色；导航栏 灰色
    private fun setStatusTextColor(joinPoint: JoinPoint) {
        val obj: Any = joinPoint.`this` ?: return
        val activity: Activity = obj as? Activity ?: return

        MdStatusBar.StatusBuilder.init()
            .setStatusColor(0, 0, "titleTxtColor")
            .setNavColor(0, 0, "txtLight")
            .setApplyNav(true)
            .setColorBar(activity)

        StatusBarContentColor.setStatusTextColor(activity, true, false)
    }

}